package com.permission.controller;


import com.permission.dto.request.system.ExportLoginLogRequest;
import com.permission.dto.request.system.LoginLogRequest;
import com.permission.dto.request.system.SystemLogRequest;
import com.permission.message.StandardResponse;
import com.permission.service.SysLoginLogService;
import com.permission.service.SysOperationLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * @desc: 系统日志接口
 * @projectName: permission-parent
 * @author: xhs
 * @date: 2021/12/29 16:20
 * @version: JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/api/log")
public class LogController {
    @Autowired
    private SysLoginLogService logService;
    @Autowired
    private SysOperationLogService operationLogService;

    /**
     * 分页查询登录日志
     *
     * @param logRequest
     * @return
     */
    @PostMapping("/queryLoginLog")
    public StandardResponse<Object> queryLoginLog(@Valid @RequestBody LoginLogRequest logRequest) {
        return logService.getLoginLog(logRequest);
    }

    /**
     * 分页查询系统操作日志日志
     *
     * @param logRequest
     * @return
     */
    @PostMapping("/systemLog")
    public StandardResponse<Object> systemLog(@Valid @RequestBody SystemLogRequest logRequest) {
        return operationLogService.getSystemLog(logRequest);
    }

    /**
     * 导出登录日志
     *
     * @param logRequest
     */
    @PostMapping("/exportLoginLog")
    public void exportLoginLog(@RequestBody ExportLoginLogRequest logRequest, HttpServletResponse response) {
        logService.exportLoginLog(logRequest, response);
    }
}
